﻿using System;
using System.Collections.Generic;

namespace Citi.PTSConsolidation.Domain
{
    public partial class ClientAllocation
    {
        public static readonly Dictionary<string, string> ColumnMappings = new Dictionary<string, string> { 
                { "[Project_Id]", "ProjectId" },
                { "[Client_GOC_Code]", "ClientGocCode" } ,
                { "[Client_Percentage]", "FullYearPercent" },
                { "[Period_Year]", "PeriodYear" }
            };

        public static string GetEntrepotQueryString(int year)
        {
            return string.Format(
                @"SELECT DISTINCT Period_Year, Project_Id, Client_GOC_Code, (Client_Percentage / 100) as Client_Percentage FROM Project_Financials Financials
                INNER JOIN DSMT_GOC Client ON CLIENT_GOC_CODE = Client.GOC_ID
                INNER JOIN DSMT_GOC [System] ON SYSTEM_GOC_CODE = [System].GOC_ID
                WHERE (Client.Country = 'BR' OR [System].Country = 'BR')
                AND Period_Year = {0}", year);
        }

        public static string GetQueryUpdateAllocation(int year, DateTime referenceDate)
        {
            return string.Format(@"UPDATE BookOfWork{0}

                        SET ClientAllocation = FullYearPercent
                        from BookOfWork{0} currentBow
	                        INNER JOIN ClientAllocation ON ClientAllocation.ClientGocCode = currentBow.ClientGocCode
		                        AND ClientAllocation.ProjectId = currentBow.ProjectId AND ClientAllocation.PeriodYear = {0}
                        WHERE currentBow.ReferenceDate = '{1}'",
               year, referenceDate.ToString("yyyy-MM-dd"));
        }

        public static string GetQueryDelete()
        {
            return "DELETE FROM ClientAllocation";
        }
    }
}
